package com.gyh.stlserver.util;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;

/* 统一返回结果 */
@Data
@NoArgsConstructor
@AllArgsConstructor
@Accessors(chain = true)
public class Result {
    private Integer code;
    private String msg;
    private Object data;

    /*返回成功的响应*/
    public static Result success(Integer code,String msg,Object data){
        Result result = new Result();
        result.setCode(code);
        result.setMsg(msg);
        result.setData(data);
        return result;
    }
    public static Result success(Integer code,Object data){
        Result result = new Result();
        result.setCode(code);
        result.setData(data);
        return result;
    }
    public static Result success(Integer code,String msg){
        Result result = new Result();
        result.setCode(code);
        result.setMsg(msg);
        return result;
    }
    public static Result success(Integer code){
        Result result = new Result();
        result.setCode(code);
        return result;
    }

    /*返回失败的响应*/
    public static Result error(Integer code,String msg,Object data){
        Result result = new Result();
        result.setCode(code);
        result.setMsg(msg);
        result.setData(data);
        return result;
    }
    public static Result error(Integer code,String msg){
        Result result = new Result();
        result.setCode(code);
        result.setMsg(msg);
        return result;
    }

}
